#pragma once
#include "Common.h"

// string 包括所有STL容器都不是final类，但是不要继承！
class AB final : public string
{
public:
    AB(int num = 0, const string &str = "")
        : string(str),
          _num(num)
    {
    }

    int _num = 0;
};

// class BA : AB //不能继承final类
// {
// };

class Base
{
public:
    // virtual void Func() = 0;
    virtual ~Base() = 0; // 将析构函数声明为pure virtual

private:
    int _b;
};

Base::~Base()
{
    cout << "~Base()" << endl;
}

class Derived : public Base
{
public:
    // virtual void Func() override
    // {
    //     cout << "Derived::Func" << endl;
    // }
    
    virtual ~Derived() override
    {
        cout << "~Derived()" << endl;
    }

private:
    int _d;
};

void Test_FinalClass()
{
    // string等标准库中提供的类是否为final类
    // AB *pab = new AB(10, "abc");
    // cout << pab->_num << endl;
    // cout << *pab << endl;
    // string *pstr = pab;
    // delete pstr; // 局部销毁，内存泄漏
    // cout << pab->_num << endl;
    // cout << *pab << endl;

    // pure virtual函数
    // Base b;
    Derived d;
}